package io.gitee.hefren.hhconfig.demo.beans;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;

/**
 * @Date 2024/5/29
 * @Author lifei
 */
public class Cat implements BeanNameAware, BeanFactoryAware, EnvironmentAware, ApplicationContextAware, InitializingBean, DisposableBean {

    // Step 6. 初始化属性值
    private String color;

    public Cat() {
        System.out.println("====> Step 3. Cat Constructor.....");
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("===> Step 7. BeanNameAware  setBeanName: " + name);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("===> Step 8. BeanFactoryAware setBeanFactory: " + beanFactory.getClass().getName());
    }

    @Override
    public void setEnvironment(Environment environment) {
        System.out.println("===> Step 9. EnvironmentAware setEnvironment: " + environment.getClass().getName());
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("===> Step 10. ApplicationContextAware setApplicationContext: " + applicationContext.getClass().getName());
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("===> Step 12. InitializingBean.afterPropertiesSet()");
    }

    public void init() {
        System.out.println("==> Step 13. initMethod..... ");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("===> Step 15. DisposableBean.destroyMethod..... ");
    }

    public void stop() {
        System.out.println("==> Step 16. destroyMethod..... ");
    }
}
